Conversation
|
Is there a related issue, or how did you come across this? Could you show another compliant CLDR implementation producing |
|
Thanks for asking. I don't have a related issue to link. I'm working on a project that automates finding and submitting bug-fix PRs and compatibility issues to GitHub projects with active contributor communities. This PR came out of that workflow, which checked The specific discrepancy is that I have now independently checked ICU4J 78.1 on Java 21. It produces import java.math.BigDecimal;
import com.ibm.icu.number.NumberFormatter;
import com.ibm.icu.number.Precision;
import com.ibm.icu.text.PluralRules;
import com.ibm.icu.text.PluralRules.Operand;
import com.ibm.icu.util.ULocale;
class CheckOperands {
public static void main(String[] args) {
var rules = PluralRules.forLocale(new ULocale("lv"));
for (String s : new String[]{"0.001", "0.00100", "0.011", "0.11", "0.000"}) {
var input = new BigDecimal(s);
var formatted = NumberFormatter.withLocale(ULocale.ROOT)
.precision(Precision.fixedFraction(Math.max(0, input.scale())))
.format(input);
var operands = formatted.getFixedDecimal();
System.out.printf("%s: v=%.0f w=%.0f f=%.0f t=%.0f lv=%s%n",
s, operands.getPluralOperand(Operand.v),
operands.getPluralOperand(Operand.w),
operands.getPluralOperand(Operand.f),
operands.getPluralOperand(Operand.t), rules.select(formatted));
}
}
}With the ICU4J 78.1 JAR, run The explicit fraction precision preserves the visible digits of the input, including trailing zeros, matching the All five operand/category results match this PR. I also reran The original investigation, this cross-check, and this reply were prepared with Codex assistance. |
extract_operands()undercounts visible fractional digits for numbers below 1 when the fractional part starts with zeros. For example,Decimal('0.001')currently producesv = 1, w = 1; both operands should be 3 under the CLDR operand definitions.This affects locale plural selection:
The Latvian rule distinguishes
v = 2fromv != 2.Decimal.as_tuple().digitsomits leading fractional zeros, so the current calculation treats0.011like a number with two fractional digits.Compute
vfrom the decimal exponent and derivewby subtracting the trailing-zero count. Fractional valuesfandtretain their existing calculation. Tests cover leading zeros, trailing zeros, signed values, decimal zero, a positive exponent, float input, custom plural rules, and the Latvian locale rule.Validation on Windows / Python 3.13.13 with the repository's CLDR 48.2 import:
python -m pytest tests/test_plural.py -q: 49 passed.python -m pytest -q: 7839 passed, 9 skipped, 2 xfailed.git diff --checkpasses.AI assistance: Prepared with Codex. The reproducer and tests listed above were executed locally.